<?php
    $this->title = "Eventi";
    $this->headTitle($this->title);
?>
<?php
    $disco      = $this->disco;
    $day        = $this->day;
    $discoName  = $this->discoName;
    $paese      = $this->paese;
    $allDisco   = $this->allDisco;
    $zonaList   = $this->zonaList;
?>
<?php
/**
 * dispay all "paese" in  sponsor1
 */
$line2 = '<div id="box">';
foreach ($paese as $key=>$paese2){
    $line2_new = '<h2><a href="'. $this->url(array('controller'=>'Index',
                                                   'action'=>'show-town',
                                                   'name'=> $paese2
                                                   ), 'index', TRUE) .'">' . $paese2
               . '</a></h2>';
    $line2 = $line2 . $line2_new;
    }
$line2 = $line2 . '</div>';
//$this->layout()->sponsor1 = $line2;

/**
 *  dispay all disco in  sponsor0
 */
$line = '<div id="box">';
foreach ($allDisco as $key=>$allDisco2){
    $line_new = '<h2><a href="'. $this->url(array('controller'=>'Club',
                                                  'name'=> $allDisco2[0],
                                                   ), 'locale', TRUE) .'">' . $allDisco2[1]
              . '</a></h2>';
    $line = $line . $line_new;
    }
$line = $line . '</div>';
$this->layout()->sponsor0 = $line;

/**
 * dispay all "provincia" in  provincia
 */
$line4 = '';
foreach ($zonaList as $key=>$zonaList2){
    $line4_new = '<h2><a href="'. $this->url(array('controller'=>'Index',
                                                    'action'=>'provincia',
                                                    'id'=> $zonaList2,
                                                   ), 'index', TRUE) .'">' . $zonaList2 . '</a></h2>';
    $line4 = $line4 . $line4_new;
    }
$line4 = $line4 . '';
$this->layout()->provincia = $line4;
?>

<div id="scroller_container">
 <div id="scroller">
    <h2 class="welcome">
        Benvenuto su whichclub.. ..tutti gli eventi dei tuoi locali preferiti..
        partecipa alle feste più esclusive! Organizza con noi la tua serata!
    </h2>
 </div>
</div>
    <?php
        if ($day!='all'){
            $yyyy=strtok($day, "-");
            $mesi = array(
                    'Gennaio',
                    'Febbraio',
                    'Marzo',
                    'Aprile',
                    'Maggio',
                    'Giugno',
                    'Lulgio',
                    'Agosto',
                    'Settembre',
                    'Ottobre',
                    'Novembre',
                    'Dicembre');
            $mm=strtok("-");
            switch ($mm) {
                case 1:
                    $mm = $mesi[0];
                    break;
                case 2:
                    $mm = $mesi[1];
                    break;
                case 3:
                    $mm = $mesi[2];
                    break;
                case 4:
                    $mm = $mesi[3];
                    break;
                case 5:
                    $mm = $mesi[4];
                    break;
                case 6:
                    $mm = $mesi[5];
                    break;
                case 7:
                    $mm = $mesi[6];
                    break;
                case 8:
                    $mm = $mesi[7];
                    break;
                case 9:
                    $mm = $mesi[8];
                    break;
                case 10:
                    $mm = $mesi[9];
                    break;
                case 11:
                    $mm = $mesi[10];
                    break;
                case 12:
                    $mm = $mesi[11];
                    break;
            }
            $dd=strtok("-");
            $day_new =$dd . " " . $mm . " " . $yyyy;
            echo "<h3 class='welcome'>Eventi del giorno $day_new</h3>";
        } else {
            echo "<p></p>";
        }

 echo '<p id="catpicker">';
        if (count($discoName)==1 || $day!='all'){
            ?>
            <a href="
            <?php
                echo $this->url(array('controller'=>'Index',
                                      'action'=>'eventi'), 'index', TRUE);
            ?>
               ">TUTTI</a> |
    <?php
        } else {
    ?>
            <a href="
            <?php
                echo $this->url(array('controller'=>'Index',
                                      'action'=>'eventi'), 'index', TRUE);
            ?>
               " id="allcat" class="current">TUTTI</a> |
    <?php
        }

    ?>
<!-- visualizzo i giorni [lun - mar - mer ecc] -->
<?php
    /*
    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Mon'),
                    'index', TRUE);
    echo '">L</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Tue'),
                    'index', TRUE);
    echo '">M</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Wed'),
                    'index', TRUE);
    echo '">M</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Thu'),
                    'index', TRUE);
    echo '">G</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Fri'),
                    'index', TRUE);
    echo '">V</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Sat'),
                    'index', TRUE);
    echo '">S</a> |';

    echo '<a href="';
    echo $this->url(array(
                    'controller'=>'index','action'=>'eventi', 'days'=> 'Sun'),
                    'index', TRUE);
    echo '">D</a> |';
    */
 ?>  
<?php
if ($day!='all'){
    require_once "models/Db/Event_db.php";
    $eventHandle = new Event_db();
    $discoName = array();
    $pivaList2 = $eventHandle->discoActiveEventsByData($day);
    foreach ($pivaList2 as $pivaList3){
            $piva = $pivaList3['piva'];
            $temp = $eventHandle->getNameDsicoByPiva($piva);
            $discoName[] = $temp['name'];
            }
    $discoName = array_unique($discoName);
    $discoName=$discoName;
    foreach ($discoName as $key=>$discoName2){
        echo '<a href="#" id="'. str_replace(" ", "", trim($discoName2)) .'" class="filter">'. $discoName2 . '</a> | ';
    }//end foreach
} else {
    foreach ($discoName as $key=>$discoName2){
        echo '<a href="#" id="'. str_replace(" ", "", trim($discoName2)) .'" class="filter">'. $discoName2 . '</a> | ';
    }
}
    echo "</p>";
?>
<?php
    require_once "models/Db/Event_db.php";
    require_once "models/Utility/Utility.php";

    $utility_obj = new Utility();
    $eventHandle = new Event_db();

    foreach ($disco as $discoElement){

        //usa event_db per recuperare il nome
        $piva = $discoElement['piva'];
        $id_evento = $discoElement['id'];

        $discoName3 = $eventHandle->getNameDsicoByPiva($piva);
        $thumb = $eventHandle->getThumbByID($id_evento);
        $thumb_path = $thumb['thumb_path'];
        $titolo_evento = $discoElement['titolo'];
        $html_descrizione = html_entity_decode($discoElement['descrizione']);
        $descrizione = $utility_obj->trim_body(strip_tags($html_descrizione), 100);
        $data = $discoElement['data_inizio'];
?>
<a id="discount-item_a"href="#" >
    <div class="discounted-item <?php
                                echo str_replace(" ", "", trim($discoName3['name'])) ?>" rel="<?php
                                echo $this->url(array(
                                    'controller'=>'Index',
                                    'action'=>'evento',
                                    'id'=>"0_" . $id_evento), 'index', TRUE);
         ?>">
        <div class="reasonbar">
            <div class="prod-title" style="width: 65%;"><?php echo $titolo_evento ?></div>
            <div class="reason" style="width: 29%;"><span class="dname"><?=$discoName3['name']?></span> <?=$data?></div>
        </div>
        <img src="/<?php echo $thumb_path ?>" alt="flayer" />
<!--
        <div class="discount-bar">
            <?php// echo $descrizione; ?>
        </div>
-->
    </div>
</a>
<?php
    }
//echo "</form>";
?>